/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package itcast;

import java.util.Calendar;

/**
 * <p>Project: JavaStudy - CalendarDemo
 * <p>Powered by jiangbo On 2023-02-01
 * 20:52:06
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class CalendarDemo {
    public static void main(String[] args) {
//1 实例化，支持国际化，功能强，官方建议使用
        Calendar c = Calendar.getInstance();
//getTime() 返回一个Date实例，将Calendar 转换为 Date类
//Date d = c.getTime();
//2.add 增加
//c.add(Calendar.DATE,-7);
//任何数据，离开日期就是无效数据
//c.add(Calendar.HOUR,10);
//c.add(Calendar.MONTH,-25);
//3.set 设置
//2000 3 22 08 30 30 出生
        c.set(2000,9-1,16,23,56,44);
//4.get 读取
        System.out.println(c.get(Calendar.YEAR));
        System.out.println(c.get(Calendar.MONTH) + 1);
        System.out.println(c.get(Calendar.DATE));
//12小时制 8点
        System.out.println(c.get(Calendar.HOUR));
//24小时制 20点
        System.out.println(c.get(Calendar.HOUR_OF_DAY));
        System.out.println(c.get(Calendar.MINUTE));
        System.out.println(c.get(Calendar.SECOND));
        System.out.println(c.get(Calendar.MILLISECOND));
//6 代表周五
        System.out.println(c.get(Calendar.DAY_OF_WEEK));
        System.out.printf("%tF %<tT %<tA%n", c);

        long ms = System.currentTimeMillis() - c.getTimeInMillis();
        System.out.println(ms);
        System.out.println("所活天数："+ms / (1000*60*60*24));
        //星期几
        Calendar week = Calendar.getInstance();
        week.set(2023,1,1);
        long week2 = week.getTimeInMillis();
        System.out.printf("%tA%n",week2);
//当前7天前日期，5天后日期
        long ms2 = 7*1000*60*60*24;
        long ms3 = 5*1000*60*60*24;
        long Date2 = System.currentTimeMillis()-ms2;
        long Date3 = System.currentTimeMillis()+ms3;
        System.out.printf("%tF %<tT %<tA%n",Date2);
        System.out.printf("%tF %<tT %<tA%n",Date3);


    }
}


